package com.ymttest.database.sqlwapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.utils.EnvSetup;
/************************************************************************************
 * @File name :SearchWapper.java
 * @Author : shuhongtao
 * @Date : 2016年4月13日
 * @Copyright : M端搜索相关
 ************************************************************************************/
public class SearchWapper {
	SqlManager manage;

	public SearchWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}
	
	/**
	 * 根据uid查找店主在惩罚表中的信息
	 * @param uid 
	 * */
	public List<Map> selectUserPunishInfo(int uid){
		List<Map> list = manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectUserPunishInfo",uid);
		return list;
		
	}
	
	/**
	 * 根据uid查找店主是买手还是商户
	 * @param uid 
	 * */
	public List<Map> selectSellerType(int uid){
		List<Map> list = manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectSellerType",uid);
		return list;
		
	}
	
	/**
	 * 查找出所有满足要求的店铺总数
	 * 
	 * */
	public int selectSellerNum(){
		
		int num = (Integer) manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectSellerNum",null).get(0);
		return num;
		
	}

	/**
	 * 根据productid查找商品信息
	 * @param uid 
	 * */
	public List<Map> selectProductInfo(String productid){
		List<Map> list = manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectProductInfo",productid);
		return list;
		
	}
	
	/**
	 * 查找出商品对应的隐藏时间
	 * 
	 * */
	public List<Map> getHiddenProductInfo(String productid){
		
		List<Map> list =  manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectHiddenProductInfo",productid);
		return list;
		
	}
	

	
	/**
	 * 查找商户是否在白名单中
	 * */
	public boolean getSellerAttributeInfo(int uid){
		
		List<Map> SellerAttributeInfo = manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectSellerAttribute",uid);
		if(SellerAttributeInfo.size()>0){
			return true;
		}else{
			return false;
		}
		
		
	}
	
	/**
	 * 查找M端有效商品
	 * 
	 * */
	public List<Map> getProductBySellerId(int uid,String iBrandId,String iThirdCategoryId,String sProductId){
		Map map=new HashMap();
		map.put("uid", uid);
		map.put("iBrandId", iBrandId);
		map.put("iThirdCategoryId", iThirdCategoryId);
		map.put("sProductId", sProductId);
		List<Map> list =  manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectProduct",map);
		return list;
		
	}
	
	/**
	 * 查找类目cateid
	 * */
	public List<Map> getCateId(String cateid){
		Map map=new HashMap();
		map.put("cateid", cateid);
		List CateIdInfo = manage.getSelectResults("com.ymttest.database.mapping.SearchMapper.selectCateId",map);
		return CateIdInfo;
	}
	
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		
		//List<Map> aa = new SearchWapper().getProductBySellerId(0,"","","8ff46563-d194-4332-908c-e2708e4d7513");
		/*String cateid = "1922";
		List<Map> AA = new SearchWapper().getCateId(cateid);
		Logger.debug(AA);*/
		
		
	}

	
}
